#!/usr/bin/env python
import os
import sys
import time
import zipfile
import json
import shlex

#read the argument string from the arguments file
arguments = sys.argv[1:]
t=time.strftime('%Y-%m-%d-%H',time.localtime(time.time()))

args = {}
for arg in arguments:
    if "=" in arg:
        e = arg.split("=")
        args[e[0]] = e[1]

if 'path' in args.keys() and 'src' in args.keys():
    f = zipfile.ZipFile("%s/%s-root.zip" %(args['path'],t),'w',zipfile.ZIP_DEFLATED)
    startdir = "%s" %(args['src'])
    for dirpath, dirnames, filenames in os.walk(startdir):
        for filename in filenames:
            f.write(os.path.join(dirpath,filename))
    f.close()
    print json.dumps({
        "changed" : True,
        "msg" : "Compress Success."
    })
    sys.exit(0)
else:
    print json.dumps({
        "failed" : True,
        "msg" : "Failed Compress."
    })